<?php

//Este puede crear y editar usuarios de la empresa
class MenuOrganizationAdmin extends Node
{

    protected $section_policy = 'enterprises_list';

    function setSection( $section )
    {

        if ( in_array( $section,
                        array( 'enterprises_list', 'users_organization_list' ) ) )
                $this->section_policy = $section;
        else $this->errors[ ] = 'Sección incorrecta';
    }

    function handleFriendly()
    {
        $this->_setSection( self::popFriendlyParam() );
    }

    function handleGET( Event $e )
    {
        if ( $e->tag == 'change_section' ) {

            $this->_setSection( $_GET[ 'section' ] );
            $e->cancelBubble();
        }
    }

    function fill()
    {

        if ( empty( $_SESSION[ 'organization' ] ) )
                $_SESSION[ 'organization' ] = MyLink::$default->get_rows( 'SELECT organization FROM users WHERE id=' . User::getLogged()->getId(),
                            true )->getField( 0 );

        if ( empty( $_SESSION[ 'organization' ] ) ) //si el superadministrador que no tiene organizacion se queda sin sesion
                User::getLogged()->resetRoles();
        else
                $this->appendChild( Node::getInstance( $this->section_policy ),
                    $_SESSION[ 'organization' ] );

        $this->pushFriendlyURL( $this->section_policy );
    }

}

?>
